{extend name="public/base" /}
{block name="style"}
<style>
 .layui-table-cell {
       height: auto;
       line-height: 24px;
       white-space: normal;
       padding: 10px 15px;
    }
</style>
{/block}
{block name="button"}
<button data-modal='{:url("add")}' data-title="添加会员" class='layui-btn layui-btn-sm layui-btn-primary'>添加会员</button>
{/block}
{block name="content"}
        <form class="layui-form layui-form-pane form-search" action="{:url()}" onsubmit="return false" method="post" autocomplete="off">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">邮箱</label>
                <label class="layui-input-inline">
                    <input name="email" value="" placeholder="" class="layui-input">
                </label>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">用户状态</label>
                <div class="layui-input-inline">
                    <select name="status" lay-search class="layui-select">
                        <option value='0'>全部</option>
                        <option value='1'>启用</option>
                        <option value='-1'>禁用</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">登录时间</label>
                <div class="layui-input-inline">
                    <input data-date-range name="login_at" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </form>
        <table id="MemberTable"  data-url="{:url('index')}" data-target-search="form.form-search"></table>
{/block}
{block name='script'}
<script>
    $(function () {
        $.menu.highlight_subnav("{:url('index')}")
        $('#MemberTable').layTable({
            even: true,
            height: 'full',
            method: 'post',
            url: "{:url('index')}" ,
            page: true,
            cols: [[
                {field: 'email', title: '会员资料',width:220, align: 'left',templet:function (d) {
                    var id = $.trim(d.id);
                     str ='<a href="/financial-log/index?member_id='+id+'">'+id+'</a><br/>';
                     str += '<span>邀请码：'+d.invite_code+'</span><br/>';
                     str +='<span "data-copy">账号：'+d.email+'</span><br/>';
                     str +='<span>注册时间：'+d.register_at+'</span>'
                     return str;
                 }},
                {field: 'is_agent', title: '是否代理', align: 'center',width: 80,templet:function (d){
                    return d.is_agent ==1 ? "是":"否";
                }},
                {field: 'status', title: '登录状态', align: 'left', width: 180, templet: '#StatusSwitchTpl'},
                {field: 'withdraw_status', title: '提现状态', align: 'left', width: 120, templet: '#WithdrawStatusSwitchTpl'},
                {field: 'audit_status', title: '认证状态', align: 'left', width: 90, templet:function (d){
                          const audit_status ={0:"未认证",1:"认证中",2:"认证通过",3:"认证拒绝"};
                          return audit_status[d.audit_status];
                    }},
                {field: 'son', title: '推荐人', align: 'left', width: 200, templet:function (d){
                    var str ="";
                     $.each(d.son,function (k,v) {
                         var count =1;
                         count +=k;
                         email = v.email
                         str+="<a href=''>"+count+"代："+email+"<a/><br/>";

                     })
                    return str;
                }},
                {field: 'login_time', title: '登录IP/时间/地址', align: 'left',width:250,templet:function (d){
                        str = '<span>ip：'+d.login_ip+'</span><br/>';
                        str +='<span>登录时间：'+d.login_at+'</span><br/>'
                        str +='<span>登录地址：'+d.login_address+'</span>';
                        return str;
                 }},
                {toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 350, fixed: 'right'}
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 :-1};
            $.form.post("{:url('setStatus')}",data,function (){
                $('#MemberTable').trigger('reload');
            },2)
        });
        layui.form.on('switch(WithdrawStatusSwitch)', function (obj) {
            var data = {id: obj.value, withdraw_status: obj.elem.checked > 0 ? 1 : -1};
            $.form.post("{:url('setWithdrawStatus')}",data,function (){
                $('#MemberTable').trigger('reload');
            },2)
        });
    });
    function setAgent(id) {
       var index =  $.msg.confirm("确认设置代理吗？",function (){
            $.post("{:url('setAgent')}",{id:id,is_agent:1},function (res){
                if (res.code >1) {
                    $.msg.error(ret.msg, 3, function () {
                        $('#MemberTable').trigger('reload');
                    });
                } else {
                    $.msg.success("设置成功",3,function (){
                        $('#MemberTable').trigger('reload');
                    })
                }
            },'json')
        },function (){
           layer.close(index);
        })
    }
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="正常|冻结" lay-filter="StatusSwitch" {{-d.status==1?'checked':''}}>
    {{-d.status==1 ? '<b class="color-green">正常</b>' : '<b class="color-red">冻结</b>'}}
</script>

<script type="text/html" id="WithdrawStatusSwitchTpl">
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁止" lay-filter="WithdrawStatusSwitch" {{-d.withdraw_status==1?'checked':''}}>
    {{-d.withdraw_status==1 ? '<b class="color-green">正常</b>' : '<b class="color-red">禁止</b>'}}
</script>

<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-sm"  data-title="编辑用户" data-modal='{:url("edit")}?id={{d.id}}'>编辑</a>
    <a class="layui-btn layui-btn-sm layui-btn-normal" data-title="审核认证" data-modal='{:url("audit")}?id={{d.id}}'  {{-d.audit_status!="1" ? 'style="display:none;"' : ''}}>审核认证</a>
    <a class="layui-btn layui-btn-sm layui-btn-warm" data-title="充值" data-modal='{:url("pay")}?id={{d.id}}'>充值</a>
    <a class="layui-btn layui-btn-sm layui-btn-primary"     data-modal='{:url("letter/add")}?id={{d.id}}'>发送通知</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger"     {{-d.pid!=0 ||d.is_agent=="1" ? 'style="display:none;"' : ''}}   onClick="setAgent('{{d.id}}')">设置代理</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger"     data-modal='{:url("wallet")}?id={{d.id}}'>钱包</a>
</script>
{/block}
